package com.yitao.cms.service.order;


import com.skipper.base.service.GenericEntityService;
import com.yitao.client.constant.OrderStatusEmnu;
import com.yitao.client.dto.order.SynchronousOrderDto;
import com.yitao.client.model.order.QSynchronousOrderModel;
import com.yitao.client.model.order.SynchronousOrderModel;
import com.yitao.cms.utils.BaseUtils;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.transaction.Transactional;
import java.util.List;


@Service
public class SynchronousOrderService extends GenericEntityService<SynchronousOrderModel, SynchronousOrderDto, QSynchronousOrderModel> {
    private BaseUtils base = BaseUtils.getInstance();

    public SynchronousOrderService(EntityManager entityManager) {
        super(entityManager);
    }

    public List<SynchronousOrderModel> getSynchronousOrderModelByFormerOrderCodeAndSynchronousStatus( String fatherOrderCode) {
        return queryFactory.select(Q).from(Q).where(Q.formerOrderCode.eq(fatherOrderCode).and(Q.synchronousStatus.eq(1))).fetch();
    }

    public List<SynchronousOrderModel> getSynchronousOrderModelBySynchronousOrderCodeCodeAndSynchronousStatus(String fatherOrderCode) {
        return queryFactory.select(Q).from(Q).where(Q.synchronousOrderCode.eq(fatherOrderCode).and(Q.synchronousStatus.eq(1))).fetch();
    }

    @Transactional
    public void save(SynchronousOrderModel synchronousOrderModel) {
        repository.save(synchronousOrderModel);
    }
}
